package com.vincent.kdp.ui.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.vincent.baseapp.base.BaseFragment;
import com.vincent.baseapp.util.SPUtil;
import com.vincent.kdp.R;
import com.vincent.kdp.contract.NewChildContract;
import com.vincent.kdp.presenter.NewChildPresenter;
import com.vincent.kdp.ui.bean.entity.NewCommodity;
import com.vincent.kdp.ui.bean.response.NewCommodityListOutput;
import com.vincent.kdp.ui.commodity.CommodityListActivity;
import com.youth.banner.Banner;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by jingjing on 2017/4/17.
 */

public class NewChildFragment extends BaseFragment<NewChildContract.View, NewChildPresenter> implements NewChildContract.View {

    @Bind(R.id.new_banner)
    Banner mNewBanner;
    @Bind(R.id.new_child_title)
    TextView mNewChildTitle;
    @Bind(R.id.new_child_content)
    TextView mNewChildContent;

    private NewCommodityListOutput output;
    private String title;
    //存放图片的集合
    private ArrayList<String> mList = new ArrayList<>();
    //当前显示的坐标
    private int selectPosition;

    public static NewChildFragment getInstance(String title, NewCommodityListOutput output) {

        NewChildFragment child = new NewChildFragment();

        Bundle bundle = new Bundle();
        bundle.putString("childFragment", title);
        bundle.putSerializable("data", output);
        child.setArguments(bundle);

        return child;

    }

    @Override
    protected int getLayoutResId() {
        return R.layout.new_child_fragment;
    }

    @Override
    protected void initViewData() {
        Bundle bundle = getArguments();
        //所有数据
        output = (NewCommodityListOutput) bundle.getSerializable("data");
        List<NewCommodity> data = output.getData();
        //当前标题
        title = bundle.getString("childFragment");
        for (int x = 0; x < data.size(); x++) {
            if (title.equals(data.get(x).getSeriesName())) {
                selectPosition=x;
                mNewChildTitle.setText(data.get(x).getName());
                mNewChildContent.setText("\t\t\t"+data.get(x).getRemark());
                mList.clear();
                mList.addAll(Arrays.asList(data.get(x).getImage().split(",")));
                presenter.autoScrollow(mNewBanner, mList);
            }
        }

        dismissLoadDialog();

    }

    @Override
    public NewChildPresenter initPresenter() {
        return new NewChildPresenter();
    }


    @Override
    public void clickPosition(int position) {
        SPUtil.put("seriesId",output.getData().get(selectPosition).getSeriesId());
        SPUtil.put("seriesName",output.getData().get(selectPosition).getSeriesName());
        mContext.startActivity(new Intent(mContext, CommodityListActivity.class));

    }


}
